﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CustomTextbox
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:ScriptManager runat=server></{0}:ScriptManager>")]
    public class ScriptManager : Literal
    {

        protected override void Render(HtmlTextWriter writer)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(@"<script type=""text/javascript"">").Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(@"    $(document).ready(function () {").Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(@"        $('.watermark').focus(function () {").Append(Environment.NewLine);
            sb.Append(@"            $tb = $(this);").Append(Environment.NewLine);
            sb.Append(@"            if ($tb.val() == this.title) {").Append(Environment.NewLine);
            sb.Append(@"                $tb.val("""");").Append(Environment.NewLine);
            sb.Append(@"                $tb.removeClass(""watermark"");").Append(Environment.NewLine);
            sb.Append(@"            }").Append(Environment.NewLine);
            sb.Append(@"        });").Append(Environment.NewLine);
            sb.Append(Environment.NewLine);

            sb.Append(@"        $('.watermark').blur(function () {").Append(Environment.NewLine);
            sb.Append(@"            $tb = $(this);").Append(Environment.NewLine);
            sb.Append(@"            if ($.trim($tb.val()) == """") {").Append(Environment.NewLine);
            sb.Append(@"                $tb.val(this.title);").Append(Environment.NewLine);
            sb.Append(@"                $tb.addClass(""watermark"");").Append(Environment.NewLine);
            sb.Append(@"            }").Append(Environment.NewLine);
            sb.Append(@"        });").Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(@"    });").Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(@"</script>").Append(Environment.NewLine);

            sb.Append(Environment.NewLine);
            sb.Append(@"<style type=""text/css"">").Append(Environment.NewLine);
            sb.Append(@"    .watermark").Append(Environment.NewLine);
            sb.Append(@"    {").Append(Environment.NewLine);
            sb.Append(@"        color: Gray;").Append(Environment.NewLine);
            sb.Append(@"    }").Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(@"    .passwordTextBox").Append(Environment.NewLine);
            sb.Append(@"    {").Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(@"    }").Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(@"    .requiredTextBox").Append(Environment.NewLine);
            sb.Append(@"    {").Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.Append(@"    }").Append(Environment.NewLine);
            sb.Append(@"</style>").Append(Environment.NewLine);
            sb.Append(Environment.NewLine);

            writer.Write(sb.ToString());
        }

    }
}
